package com.thb.pay.agent.controller;


import com.thb.pay.agent.entity.AgentChannel;
import com.thb.pay.agent.service.AgentChannelService;
import com.thb.pay.api.agent.AgentChannelServiceApi;
import com.thb.pay.api.agent.vo.req.AgentChannelReq;
import com.thb.pay.api.agent.vo.resp.AgentChannelVo;
import com.xiaoleilu.hutool.bean.BeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * <p>
 * 代理商-通道表 前端控制器
 * </p>
 *
 * @author lucky
 * @since 2019-07-21
 */
@Controller
public class AgentChannelController implements AgentChannelServiceApi {

    @Autowired
    private AgentChannelService agentChannelService;

    @Override
    public List<AgentChannelVo> findListByAgentId(@RequestParam("agentId") Long agentId) {
        return agentChannelService.findAllByAgentId(agentId);
    }

    @Override
    public AgentChannelVo getByAgentIdAndProductId(@RequestParam("agentId") Long agentId, @RequestParam("productId") Long productId) {
        return agentChannelService.getByAgentIdAndProductId(agentId, productId);
    }

    @Override
    public void addOrUpdate(@RequestBody AgentChannelReq agentChannelReq) {
        AgentChannel agentChannel = new AgentChannel();
        BeanUtil.copyProperties(agentChannelReq, agentChannel);
        agentChannelService.insertOrUpdate(agentChannel);
    }
}
